<?php 
require_once("../Core/Common.php");
header('Content-type:text/html; Charset=utf-8');
use xfyzf\api\controller\AlipayService_notify;
$trade_no = $_REQUEST['out_trade_no'];

$sql = "SELECT * FROM pay_order WHERE trade_no=:trade_no limit 1";
$params = [
        'trade_no' => $trade_no
    ];
unset($_REQUEST['s']);
$srow =  safeSqlQuery($sql, $params)['result'][0];
 if(!$srow)sysmsg('该订单号不存在，请返回来源地重新发起请求！');
$sql = "SELECT * FROM pay_qrlist WHERE id='{$srow['qr_id']}' limit 1";
$QR_row = executeSQLQuery($sql);
$sql = "SELECT * FROM pay_user WHERE pid='{$srow['pid']}' limit 1";
$userrow = executeSQLQuery($sql);
$alipayPublicKey=$QR_row['alipayPublicKey'];//支付宝公钥
$aliPay = new AlipayService_notify($alipayPublicKey);
$result = $aliPay->rsaCheck($_REQUEST,$_REQUEST['sign_type']);

if($result===true && $_REQUEST['trade_status'] == 'TRADE_SUCCESS' && $srow['status']==0){
     $xf_pid=$srow['pid'];
     $xf_money=$srow['price'];
     $url=creat_callback($srow);
     $data=get_curl($url['notify']);
     xfhtemail($xf_pid,$xf_money,'支付宝当面付',$srow['name'],$srow['trade_no']);  
     echo 'success';
}else{
    echo 'fales';
}
?>